package bookworm;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 
 * class we use to get names the reviewers who wrote reviews that are in our system
 * (contained in graph). It is updated when we construct the graph.
 *
 */
public class AdministratorOfAllReviewersNames 
{
	private static AdministratorOfAllReviewersNames singleInstance;
	private ConcurrentHashMap<String, Integer> reviewersNamesAndNumberOfReviewsWritten;
	private AdministratorOfAllReviewersNames()
	{
		this.reviewersNamesAndNumberOfReviewsWritten = new ConcurrentHashMap<String, Integer>();
	}
	
	public ConcurrentHashMap<String, Integer> getReviewersNamesAndReviewsWritten()
	{
		return this.reviewersNamesAndNumberOfReviewsWritten;
	}
	
	public static synchronized AdministratorOfAllReviewersNames getInstance()
	{
		if(singleInstance == null)
		{
			singleInstance = new AdministratorOfAllReviewersNames();
		}
		
		return singleInstance;
	}
	
	public void addNewReviewerName(String reviewerName)
	{
		if(this.isThisReviewerAlreadyOnList(reviewerName) == null)
		{
			this.reviewersNamesAndNumberOfReviewsWritten.put(reviewerName, 1);
		}
		else
		{
			int numberOfReviewsWritten = this.reviewersNamesAndNumberOfReviewsWritten.get(reviewerName);
			numberOfReviewsWritten = numberOfReviewsWritten + 1;
			this.reviewersNamesAndNumberOfReviewsWritten.put(reviewerName, numberOfReviewsWritten);
		}
	}
	
	public Integer isThisReviewerAlreadyOnList(String reviewerName)
	{
		return this.reviewersNamesAndNumberOfReviewsWritten.get(reviewerName);
		
	}
	

}
